package com.qfedu.service.impl;

import com.qfedu.dao.GoodsSecondTypeRepository;
import com.qfedu.pojo.entity.GoodsSecondType;
import com.qfedu.pojo.req.GoodsSecondTypeReq;
import com.qfedu.pojo.resp.BaseResp;
import com.qfedu.service.GoodsSecondTypeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName GoodsSecondTypeImpl
 * @Description TODO
 * @Author young
 * @Date 2022-09-27 14:27
 * @Version 1.0
 **/
@Service
public class GoodsSecondTypeImpl implements GoodsSecondTypeService {

    @Autowired
    GoodsSecondTypeRepository goodsSecondTypeRepository;
    @Override
    public BaseResp findAll() {
        List<GoodsSecondType> all = goodsSecondTypeRepository.findAll();
        return new BaseResp(1,"success",all,null);
    }

    @Override
    public BaseResp saveOrUpdate(GoodsSecondTypeReq goodsSecondTypeReq) {
        GoodsSecondType goodsSecondType = new GoodsSecondType();
        BeanUtils.copyProperties(goodsSecondTypeReq,goodsSecondType);
        goodsSecondTypeRepository.saveAndFlush(goodsSecondType);
        return new BaseResp().Success();
    }

    @Override
    public BaseResp deleteById(GoodsSecondTypeReq goodsSecondTypeReq) {
        goodsSecondTypeRepository.deleteById(goodsSecondTypeReq.getSecondTypeId());
        return new BaseResp().Success();
    }
}
